package Model::Presence;

use strict;
use utf8;
use Model::PresenceBase;
our @ISA=qw( Model::PresenceBase );

sub fields { [ qw/jid show resource priority status type change client_name client_version os_name tune_artist tune_title tune_source tune_length tune_track mood mood_text/ ] }
sub tablename { 'presence' }

sub showFor {
	my($self, $for)=@_;
	$self->presenceFor($for)->{show}
}

sub presenceFor {
	my($self, $for)=@_;
	$for=~m%^([^/]+)/?(.*)$%;

	my($presence)=@{ $self
				->order_raw($self->qi('priority') . ' DESC, ' . $self->qi('resource'))
				->limit(1)
				->where(
					jid => $1,
					show => { ne => 'offline' },
				)->list_all()
	};

	$presence || {};
}

1;
